
/* This class makes a button that highlights when you mouse over it*/


public class myButton{

  float buttonX1; 
  float buttonY1; 
  float buttonX2; 
  float buttonY2; 
  String buttonText;
  int buttonFill;
  int buttonFillHighlight;
  String shapeIs;
  float buttonTextSize;
  
  //default constructor assumes shape is square
  myButton(float buttonX1, float buttonY1, float buttonX2, float buttonY2, String buttonText){
    this.buttonX1 = buttonX1;
    this.buttonY1 = buttonY1; 
    this.buttonX2 = buttonX2;
    this.buttonY2 = buttonY2; 
    this.buttonText = buttonText;    
   
    buttonFillHighlight = 100;
    buttonFill = 50;
    
    shapeIs = "rect";
    
    buttonTextSize = (buttonY2- buttonY1)/4;
  }
  
  myButton(float buttonX1, float buttonY1, float buttonX2, float buttonY2, String buttonText, String shapeIs){
    this.buttonX1 = buttonX1;
    this.buttonY1 = buttonY1; 
    this.buttonX2 = buttonX2;
    this.buttonY2 = buttonY2; 
    this.buttonText = buttonText;    
   
    buttonFillHighlight = 100;
    buttonFill = 50;
    
    this.shapeIs = shapeIs;
    
    buttonTextSize = (buttonY2- buttonY1)/4;
  }
 
  
  void drawButton(){
    if(mouseX > buttonX1 && mouseX < buttonX2 && mouseY > buttonY1 && mouseY < buttonY2){
      fill(100, 100, 100, 125);
    }
    else{
      fill(50, 50, 50, 125);
    } 
    if( shapeIs.equals("rect") ){
      rectMode(CORNERS);
      noStroke();
      rect(buttonX1, buttonY1, buttonX2, buttonY2);  
    } else if (shapeIs.equals("ellipse") || shapeIs.equals("circle") ){
      ellipseMode(CORNERS);
      noStroke();
      ellipse(buttonX1, buttonY1, buttonX2, buttonY2);
    }
    fill(255);
    textAlign(CENTER, CENTER);
    textSize(buttonTextSize);
    if( buttonText.equals("triangle") ){
      fill(0);
      triangle(buttonX1 + 20, buttonY1 + 10, buttonX1 + 20, buttonY2 - 10, buttonX2-10, ((buttonY2-10)+(buttonY1+10))/2);
    } else if( buttonText.equals("pause") ){
      rectMode(CORNERS);
      fill(0);
      rect(buttonX1 + 15, buttonY1+10, buttonX1+ 25 , buttonY2 - 10);
      rect(buttonX2 - 25, buttonY1+10, buttonX2 - 15, buttonY2-10);
      rectMode(CORNER);
    }else{
      text(buttonText, (buttonX2+buttonX1)/2, (buttonY2 - buttonY1)/2 );  
    }
    
    //for map function
    rectMode(CORNER);
    ellipseMode(CORNER);
  }//end method drawButton
  
  void changeText(String newText){
    buttonText = newText;
  }
  
  void changeXCoord(float newX){
    float diff = buttonX1 - buttonX2;
    buttonX2 = newX + diff;
    buttonX1 = newX; 
  }
  
}//end class



